home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / Tool Chest / QuickDraw GX / QuickDraw GX Info / QuickDraw GX Interfaces / Interfaces & Libraries / graphics libraries / ramp library.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-30  |  2.1 KB  |  61 lines  |  [TEXT/MPS ]

  1. /* ramp library
  2.     gxShape library
  3.     by Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Robert Johnson, Keith McGreggor, Oliver Steele, David Van Brink, Chris Yerga
  4.     Copyright 1987 - 1991 Apple Computer, Inc.  All rights reserved.    */
  5.  
  6. #include "graphics libraries.h"
  7.  
  8. static gxBitmap rampBits = {nil, 1, 0, 0, 32, gxNoSpace, nil, nil};
  9.  
  10. gxShape NewRamp(register const gxColor *start, register const gxColor *end, register long count, const gxRectangle *bounds)
  11. {
  12.     if (count == 0)
  13.         count = 256;
  14.     rampBits.height = count--;
  15.     {   register gxShape rampShape = GXNewBitmap(&rampBits, nil);
  16.         register long d1 = ((long) end->element.component[0] - (long) start->element.component[0]) / count;
  17.         register long d2 = ((long) end->element.component[1] - (long) start->element.component[1]) / count;
  18.         register long d3 = ((long) end->element.component[2] - (long) start->element.component[2]) / count;
  19.         register long d4 = ((long) end->element.component[3] - (long) start->element.component[3]) / count;
  20.         gxColor accum;
  21.     
  22.         accum = *end;
  23.         do {
  24.             GXSetShapePixel(rampShape, 0, count, &accum, 0);
  25.             accum.element.component[0] -= d1;   
  26.             accum.element.component[1] -= d2;   
  27.             accum.element.component[2] -= d3;   
  28.             accum.element.component[3] -= d4;
  29.         } while (--count >= 0);
  30.         if (bounds)
  31.             GXSetShapeBounds(rampShape, bounds);
  32.         return rampShape;
  33.     }
  34. }
  35.  
  36.  
  37. void DrawRamp(const gxColor *start, const gxColor *end, long count, const gxRectangle *bounds)
  38. {
  39.     register gxShape ramp = NewRamp(start, end, count, bounds);
  40.     
  41.     GXDrawShape(ramp);
  42.     GXDisposeShape(ramp);
  43. }
  44.  
  45.  
  46. gxShape NewCommonRamp(commonColor start, commonColor end, long count, const gxRectangle *bounds)
  47. {
  48.     gxColor startColor, endColor;
  49.     
  50.     return NewRamp(SetCommonColor(&startColor, start), SetCommonColor(&endColor, end), count, bounds);
  51. }
  52.  
  53.  
  54. void DrawCommonRamp(commonColor start, commonColor end, long count, const gxRectangle *bounds)
  55. {
  56.     register gxShape ramp = NewCommonRamp(start, end, count, bounds);
  57.     
  58.     GXDrawShape(ramp);
  59.     GXDisposeShape(ramp);
  60. }
  61.